#1、try...except...语句
    #如果try中的语句没有异常，则执行try，不执行except
    #如果try中的语句有异常，则不执行try，执行except
# try:
#     print(123)
#     print(abc)
#     print(456)
# except:
#     print('哦豁，代码出错啦!')

#2、try...except...else 语句
    #try语句正常，执行try...else
    #try语句异常，执行except
# try:
#     a= int(input("请输入第一个整数"))
#     b= int(input("请输入第二个整数"))
#     result =a/ b
# except :
#     print("程序出现异常")
# else:
#     print(result)

#3、try...except...else...finally语句
    #try正常，执行try...else...finally
    #try异常，执行except...finally
# try:
#     a = int(input("请输入第一个整数"))
#     b = int(input("请输入第二个整数"))
#     result = a / b
# except:
#     print("程序出现异常")
# else:
#     print(result)
# finally:
#     print('程序结束')

#4、异常信息捕获，异常exception
    #NameError: name 'a' is not defined
# try:
#     print(a)
# except Exception as e:          #利用Exception抓取异常信息，取另外为e
#     print(f'异常类型:{type(e).__name__}')
#     print(f'异常信息:{e}')
#     print(f'{type(e).__name__}:{e}')

#5、常见的异常类型
    # NameError 通常是变量、函数没有定义
    # IndexError 通常是列表下标超出范围

try:
    # print(a)
    # lst=['a','b','c']
    # print(lst[3])
    # a = '1'+2
    # a=int('3.14')
     a=5/0
except NameError as e:
    print('变量或函数没有定义')
    print(f'{type(e).__name__}:{e}')
except IndexError as e:
    print('下标超出了范围')
    print(f'{type(e).__name__}:{e}')
except TypeError as e:
    print('数据类型错误')
    print(f'{type(e).__name__}:{e}')
except ValueError as e:
    print('值错误')
    print(f'{type(e).__name__}:{e}')
except Exception as e:          #Exception包含所有的错误信息
    print('其它错误')
    print(f'{type(e).__name__}:{e}')
